<template>
	<view>
		<view class="flex a-t">
			<view @click="select(0)" :class="num==0?'b1':''" class="w33" style="text-align: center;font-size: 14px;">
				我的出题记录
			</view>
			<view @click="select(1)" :class="num==1?'b1':''"  class="w33" style="text-align: center;font-size: 14px;">
				我的答题记录
			</view>
			<view @click="select(2)" :class="num==2?'b1':''"  class="w33" style="text-align: center;font-size: 14px;">
				好友答题记录
			</view>
		</view>

		<view style="box-sizing: border-box;padding: 0 20px;">
			<view v-for="(item,index) in lists" class="flex a-t" style="border: #ccc solid 1px;border-radius: 8px;padding: 10px;width: 100%;margin-bottom: 20px;">
				<view>
					<view class="c999 f12">{{item.createtime}}</view>
					<view class="c333 f14" style="margin-top: 10px;">
						{{item.answer_user_count==0?'暂时还没有人作答':'查看'}}
					</view>
				</view>
				<view style="margin-left: auto;">
					<button @click="golist(item)" class="button f12 cfff">查看此题</button>
				</view>
			</view>
		</view>

		<view @click="all('./ques')"
			v-if="num==0"
			class="button f14"
			style="width: 120px; text-align: center; line-height: 40px;position: fixed; z-index: 1;bottom: 50px; left: 50%; margin-left: -60px; "
		>
			重新出题
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				num:0,
				lists:[]
			}
		},
		onLoad(e) {
			uni.setNavigationBarColor({
				frontColor: '#000000',
				backgroundColor: '#ffffff'
			});
			this.settitle(e.type)
			// console.log()
			// e.type==0?this.list():this.my_subjectrecord()

		},

		methods: {
            all(e){
                uni.navigateTo({
                    url:e
                })
            },
			settitle(e){
                let self = this;

				this.num=e
				switch (e) {
					case 0:
                        uni.setNavigationBarTitle({
                            title:'我的出题记录'
                        });
                        self.list()
					    break;

                    case 1:
                        uni.setNavigationBarTitle({
                            title:'我的答题记录'
                        });
                        self.my_subjectrecord();
                        break;

                    case 2:
                        uni.setNavigationBarTitle({
                            title:'好友答题记录'
                        });
                        self.friend_answer_record();
                        break;
                }

			},
			golist(e){
				this.$u.vuex('vuex_cen',e)
				uni.navigateTo({
					url:'./list?id='+e.id+'&type='+this.num
				})
			},
			select(e){
				this.num=e
				this.settitle(e)
			},
			async list(){
				let res = await this.$u.apis.list()
				this.lists=res
			},
			async my_subjectrecord(){
				let res = await this.$u.apis.my_subjectrecord()
				this.lists=res
			},

            friend_answer_record(){
                let self = this;

                this.$u.apis.friend_answer_record().then(function (res) {
                    self.lists=res
                });
			},


		}
	}
</script>

<style>
page{
	background: #fff;
}
</style>
